package com.eks.websocket.client.controller;

import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.java_websocket.client.WebSocketClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/websocket/client")
public class TestController {

    private final WebSocketClient webSocketClient;

    @PostMapping("/send")
    public String sender(@RequestParam String message){
        webSocketClient.send(StringUtils.trimToEmpty(message));
        return "OK";
    }
}
